package com.four.bergain.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.bergain.entity.Bargain;
import com.four.bergain.service.IBargainService;
import com.four.bergain.vo.BargainPropertyVo;
import com.four.bergain.vo.BargainVo;
import com.guli.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gs
 * @since 2021-12-19
 */
@RestController
@RequestMapping("/bargain")
public class BargainController {
    @Autowired
    private IBargainService bargainService;

    /**
     * 砍价商品列表
     *
     * @param page     当前页
     * @param pageSize 每页条数
     * @return 返回值
     */
    @PostMapping("/bargainList")
    public IPage<Bargain> bargainList(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize,
            @RequestBody BargainVo vo
    ) {


        return bargainService.getList(page, pageSize, vo);
    }

    /**
     * 商品列表
     *
     * @return 返回商品列表
     */
    @GetMapping("shopList")
    public R shopList() {

        return bargainService.shopList();
    }

    /**
     * 商品详情回显
     *
     * @param manId
     * @return
     */
    @GetMapping("getShopById/{manId}")
    public R getShopById(@PathVariable("manId") Integer manId) {

        return bargainService.getShopById(manId);
    }

    /**
     * 商品的多图片回显
     *
     * @param manId
     * @return
     */
    @GetMapping("getPictureById/{manId}")
    public R getPictureById(@PathVariable("manId") Integer manId) {

        return bargainService.getPictureById(manId);
    }

    /**
     * 商品的多规格回显
     *
     * @param manId
     * @return
     */
    @GetMapping("findPropertyById/{manId}")
    public R findPropertyById(@PathVariable("manId") Integer manId) {

        return bargainService.findPropertyById(manId);
    }

    /**
     * 添加
     */
    @PostMapping("saveBargain")
    public R saveBargain(@RequestBody BargainPropertyVo bargain) {

        return bargainService.saveBargain(bargain);
    }

    /**
     * 修改
     *
     * @param bargain 需要修改的实体类
     * @return 返回值
     */
    @PostMapping("/updateBargain")
    public R updateBargain(@RequestBody BargainPropertyVo bargain) {

        return bargainService.updateBargain(bargain);
    }

    /**
     * 商品开启砍价
     * @param baId
     * @return
     */
    @GetMapping("updateStatusOne/{baId}")
    public R updateStatusOne(@PathVariable("baId")Integer baId) {

        return bargainService.updateStatusOne(baId);
    }

    /**
     * 商品关闭砍价
     * @param baId
     * @return
     */
    @GetMapping("updateStatusTwo/{baId}")
    public R updateStatusTwo(@PathVariable("baId")Integer baId) {

        return bargainService.updateStatusTwo(baId);
    }
}
